package board.action;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import board.common.PageNavigator;
import board.dao.BoardDao;
import board.vo.Board;

import com.opensymphony.xwork2.ActionSupport;

public class BoardAction extends ActionSupport implements SessionAware {

	private Map<String, Object> session;
	
	
		
	private Board board;		
	int boardnum;		
	private List<Board> boardlist;			
	private PageNavigator pagenavi;			
	private int currentPage = 1;			
	private String title, from, to;
	
		
	private File upload;					//업로드할 파일. Form의 <file> 태그의 name.
	private String uploadFileName;			//업로드할 파일의 파일명 (File타입 속성명 + "FileName")
	private String uploadContentType;		//업로드할 파일의 컨텐츠 타입 (File타입 속성명 + "ContentType")
	
	
	
	
	
	public String articleSearch() {
		System.out.println("BoardAction.articleSearch()> title: " + title + ", from: " + from + ", to: " + to);
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("title", title);  map.put("from", from);  map.put("to", to);
		
		//user.properties
		int countPerPage = Integer.parseInt(getText("board.countperpage"));		
		int pagePerGroup = Integer.parseInt(getText("board.pagepergroup"));		
		
			
		BoardDao boardDao = new BoardDao();
		int total = boardDao.getTotal(map);
		
		pagenavi = new PageNavigator(countPerPage, pagePerGroup, pagePerGroup, total);
		
		//현재 페이지에 해당하는 글 목록 읽기 (전체 레코드 중 보여줄 첫번째 글의 위치, 페이지당 글 수 )
		boardlist = boardDao.boardList(map, pagenavi.getStartRecord(), pagenavi.getCountPerPage());
		
		return SUCCESS;
	}//articleSearch()
	
	
	
	
	
	
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;

	}//setSession()



	/*
	 * getters and setters
	 */
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}

	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}

	public int getBoardnum() {
		return boardnum;
	}

	public void setBoardnum(int boardnum) {
		this.boardnum = boardnum;
	}

	public List<Board> getBoardlist() {
		return boardlist;
	}

	public void setBoardlist(List<Board> boardlist) {
		this.boardlist = boardlist;
	}

	public PageNavigator getPagenavi() {
		return pagenavi;
	}

	public void setPagenavi(PageNavigator pagenavi) {
		this.pagenavi = pagenavi;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}
	
		
	
}//class
